/**
 * 
 */
package exp.social.graph.rest;

import java.text.ParseException;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;

import exp.social.graph.business.User;

/**
 * @author Volodya Gavrysh
 * 
 */
@Path("/users")
public class UsersResource {
	@GET
	@Produces("application/xml")
	public String getXML() {
		return null;
	}
	
	@GET
	@Produces("text/html")
	public String getHtml() {
		return "REST TEST";
	}

	@GET
	@Produces("application/json")
	public String getJSON() {
		return "not implemented";
	}

	@POST
	@Consumes("application/json")
	@Produces("application/json")
	public String createUser(String representation) {
		try {
			User user = User.fromJSON(representation);
			return User.create(user.getUserName(), user.getPassword(),
					user.getInterests()).toJSON();
		} catch (ParseException e) {
			throw new WebApplicationException(400);
		}
		/*
		 * catch (InvalidJSONException e) { throw new
		 * WebApplicationException(400); } catch (ItemAlreadyExistsException e)
		 * { throw new WebApplicationException(403); }
		 */
	}
}
